package com.kizuki.net;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

public class Server {

    public static void main(String[] args) throws IOException {
        ServerSocket server = null;
        Socket client = null;
        DataInputStream disServer = null;
        DataOutputStream dosServer = null;

        try {
            server = new ServerSocket(4453);
            client =  server.accept();

            disServer = new DataInputStream(client.getInputStream());
            dosServer = new DataOutputStream(client.getOutputStream());

            String disStr = null;
            String dosStr = null;
            Scanner scanner = new Scanner(System.in);
            while (true) {
                disStr = disServer.readUTF();
                System.out.println("客户端说：" + disStr);
                dosStr = scanner.next();
                dosServer.writeUTF(dosStr);
            }
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            try {
                server.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
